<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Source: controlpanel.js</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Source: controlpanel.js</h1>

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>/**
 * @module ChiVoxSDK
 * @author Don Li &lt;kai.li@chivox.com>
 * @licence
 * Copyright (c) 2017 - 2020 ChiVox Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

import Utils from './utils';
import cfg from './config.json';

/**
 * ControlPanel类。&lt;br/>&lt;br/>
 *
 * ChiVoxSDK初始化时，录音机和播放器所需的控制面板。&lt;br/>
 * 有播放，停止播放，录音，停止录音，回放录音，停止回放等功能。(仅用于控制UI控件状态)
 */
class ControlPanel {
  constructor() {
    this.ele_records = Utils.find_all(document, cfg.selector.panel.record) || [];
    this.ele_plays   = Utils.find_all(document, cfg.selector.panel.play) || [];
    this.ele_replays = Utils.find_all(document, cfg.selector.panel.replay) || [];
  }

  /**
   * 停止播放。
   * @param {Object=} curr_ele - 要停止播放的HTML DOM节点。当前页面有多个控制面板时需要指定。
   */
  playOff(curr_ele) {
    if (curr_ele) {
      Utils.removeClass(curr_ele, 'playOn');
      Utils.addClass(curr_ele, 'playOff');
    } else {
      for (var i = 0; i &lt; this.ele_plays.length; i++) {
        Utils.removeClass(this.ele_plays[i], 'playOn');
        Utils.addClass(this.ele_plays[i], 'playOff');
      }
    }
  }

  /**
   * 开始播放。
   * @param {Object=} curr_ele - 要开始播放的HTML DOM节点。当前页面有多个控制面板时需要指定。
   */
  playOn(curr_ele) {
    if (!curr_ele &amp;&amp; this.ele_plays.length > 0) {
      curr_ele = this.ele_plays[0];
    }

    if (curr_ele) {
      Utils.removeClass(curr_ele, 'playOff');
      Utils.addClass(curr_ele, 'playOn');
    }
  }

  /**
   * 停止录音。
   * @param {Object=} curr_ele - 要停止录音的HTML DOM节点。当前页面有多个控制面板时需要指定。
   */
  recordOff(curr_ele) {
      if (curr_ele) {
          Utils.removeClass(curr_ele, 'recordOn');
          Utils.addClass(curr_ele, 'recordOff');
      } else {
          for (var i = 0; i &lt; this.ele_records.length; i++) {
              Utils.removeClass(this.ele_records[i], 'recordOn');
              Utils.addClass(this.ele_records[i], 'recordOff');
          }
      }
  }

  /**
   * 开始录音。
   * @param {Object=} curr_ele - 要开始录音的HTML DOM节点。当前页面有多个控制面板时需要指定。
   */
  recordOn(curr_ele) {
      if (!curr_ele &amp;&amp; this.ele_records.length > 0) {
          curr_ele = this.ele_records[0];
      }

      if (curr_ele) {
          Utils.removeClass(curr_ele, 'recordOff');
          Utils.addClass(curr_ele, 'recordOn');
      }
  }

  /**
   * 禁用回放功能。
   * @param {Object=} curr_ele - 要禁止回放的HTML DOM节点。当前页面有多个控制面板时需要指定。
   */
  replayDisabled(curr_ele) {
      if (curr_ele) {
          Utils.removeClass(curr_ele, 'replayOn');
          Utils.removeClass(curr_ele, 'replayOff');
          Utils.addClass(curr_ele, 'replayDisabled');

          curr_ele.setAttribute('dataRecordId', '');
      } else {
          for (var i = 0; i &lt; this.ele_replays.length; i++) {
              curr_ele = this.ele_replays[i];
              Utils.removeClass(curr_ele, 'replayOn');
              Utils.removeClass(curr_ele, 'replayOff');
              Utils.addClass(curr_ele, 'replayDisabled');

              curr_ele.setAttribute('dataRecordId', '');
          }
      }
  }

  /**
   * 停止回放功能。
   * @param {Object=} curr_ele - 要停止回放的HTML DOM节点。当前页面有多个控制面板时需要指定。
   */
  replayOff(curr_ele) {
      if (curr_ele) {
          Utils.removeClass(curr_ele, 'replayOn');
          Utils.removeClass(curr_ele, 'replayDisabled');
          Utils.addClass(curr_ele, 'replayOff');
      } else {
          for (var i = 0; i &lt; this.ele_replays.length; i++) {
              curr_ele = this.ele_replays[i];
              Utils.removeClass(curr_ele, 'replayOn');
              Utils.removeClass(curr_ele, 'replayDisabled');
              Utils.addClass(curr_ele, 'replayOff');
          }
      }
  }

  /**
   * 开始回放功能。
   * @param {Object=} curr_ele - 要开始回放的HTML DOM节点。当前页面有多个控制面板时需要指定。
   */
  replayOn(curr_ele) {
      if (!curr_ele &amp;&amp; this.ele_plays.length > 0) {
          curr_ele = this.ele_replays[0];
      }

      if (curr_ele) {
          Utils.removeClass(curr_ele, 'replayOff');
          Utils.removeClass(curr_ele, 'replayDisabled');
          Utils.addClass(curr_ele, 'replayOn');
      }
  }
}

export default ControlPanel
</code></pre>
        </article>
    </section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ChiVoxSDK.html">ChiVoxSDK</a></li><li><a href="module-ChiVoxSDK_flash.html">ChiVoxSDK/flash</a></li><li><a href="module-ChiVoxSDK_html5.html">ChiVoxSDK/html5</a></li><li><a href="module-ChiVoxSDK_lib.html">ChiVoxSDK/lib</a></li><li><a href="module-ChiVoxSDK_Paragraph.html">ChiVoxSDK/Paragraph</a></li><li><a href="module-ChiVoxSDK_score.html">ChiVoxSDK/score</a></li></ul><h3>Classes</h3><ul><li><a href="module-ChiVoxSDK_flash.FlashPlayer.html">FlashPlayer</a></li><li><a href="module-ChiVoxSDK_flash.FlashRecorder.html">FlashRecorder</a></li><li><a href="module-ChiVoxSDK_html5.Html5Player.html">Html5Player</a></li><li><a href="module-ChiVoxSDK_html5.Html5Recorder.html">Html5Recorder</a></li><li><a href="module-ChiVoxSDK_html5-VolumeBar.html">VolumeBar</a></li><li><a href="module-ChiVoxSDK_lib-EnScoreMap.html">EnScoreMap</a></li><li><a href="module-ChiVoxSDK_lib-StatusCode.html">StatusCode</a></li><li><a href="module-ChiVoxSDK_Paragraph-Paragraph.html">Paragraph</a></li><li><a href="module-ChiVoxSDK_score-Char.html">Char</a></li><li><a href="module-ChiVoxSDK_score-CnSentScore.html">CnSentScore</a></li><li><a href="module-ChiVoxSDK_score-CnWordScore.html">CnWordScore</a></li><li><a href="module-ChiVoxSDK_score-EnSentRec.html">EnSentRec</a></li><li><a href="module-ChiVoxSDK_score-EnSentScore.html">EnSentScore</a></li><li><a href="module-ChiVoxSDK_score-EnWordScore.html">EnWordScore</a></li><li><a href="module-ChiVoxSDK_score-Phone.html">Phone</a></li><li><a href="module-ChiVoxSDK_score-Word.html">Word</a></li><li><a href="module-ChiVoxSDK-ChiVoxSDK.html">ChiVoxSDK</a></li><li><a href="module-ChiVoxSDK-ControlPanel.html">ControlPanel</a></li><li><a href="module-ChiVoxSDK-Dialog.html">Dialog</a></li><li><a href="module-ChiVoxSDK-PlayerBuilder.html">PlayerBuilder</a></li><li><a href="module-ChiVoxSDK-ProgressBar.html">ProgressBar</a></li><li><a href="module-ChiVoxSDK-RecorderBuilder.html">RecorderBuilder</a></li></ul><h3>Namespaces</h3><ul><li><a href="public.html">public</a></li><li><a href="Utils.html">Utils</a></li></ul><h3>Global</h3><ul><li><a href="global.html#Default_ChiVoxPlayer_Options">Default_ChiVoxPlayer_Options</a></li><li><a href="global.html#Default_ChiVoxRecorder_Options">Default_ChiVoxRecorder_Options</a></li><li><a href="global.html#Default_ChiVoxSDK_Options">Default_ChiVoxSDK_Options</a></li><li><a href="global.html#Default_Paragraph_Options">Default_Paragraph_Options</a></li><li><a href="global.html#get_sig">get_sig</a></li><li><a href="global.html#tts">tts</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Sep 21 2017 16:38:41 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
